﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace SmsLib
{
    [StructLayout(LayoutKind.Sequential, Size = 320)]
    internal struct SMSMessageStruct
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
        public byte[] Msg;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public byte[] PhoneNo;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public byte[] ReceTime;
    }
    [StructLayout(LayoutKind.Sequential, Size = 296)]
    internal struct SMSReportStruct
    {
        public uint Index;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
        public byte[] Msg;
        public int Success;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
        public byte[] PhoneNo;
    }
    internal class SMSMessage
    {
        [DllImport("SMSDLL.dll")]
        public static extern int SMSStartService(int nPort, uint baudRate, int parity, int dataBits, int stopBits, int flowControl, string csca);
        [DllImport("SMSDLL.dll")]
        public static extern uint SMSSendMessage(byte[] msg, byte[] phoneNumber);
        [DllImport("SMSDLL.dll")]
        public static extern int SMSGetNextMessage(out SMSMessageStruct msg);
        [DllImport("SMSDLL.dll")]
        public static extern int SMSReport(ref SMSReportStruct rept);
        [DllImport("SMSDLL.dll")]
        public static extern int SMSStopSerice();
        [DllImport("SMSDLL.dll")]
        public static extern int SMSGetLastError(byte[] err);
        [DllImport("SMSDLL.dll")]
        public static extern int SMSCommand(byte[] input, byte[] output, int sleepTime);
        [DllImport("SMSDLL.dll")]
        public static extern bool SMSSeviceStarted();
        [DllImport("SMSDLL.dll")]
        public static extern int SMSQuery(uint index);
    }
}
